import { createRouterMap, createRoute } from "./createRouterMap";

export default function createMatch(routes) {
  let pathMap = createRouterMap(routes); // [{path1: record1}, {path2: record2}]
  // 动态添加路由方法
  function addRoutes(newRoutes) {
    createRouterMap(newRoutes, pathMap);
  }
  function match(location) {
    let record = pathMap[location];
    if (record) {
      return createRoute(record, {path: location});
    }
    return createRoute(null, { path: location });
  }
  return {
    addRoutes,
    match
  };
}